import React from 'react';

class Clock extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            date: new Date().toLocaleTimeString()
        }
    }
    tick(){
        this.setState({
            date:new Date().toLocaleTimeString()
        })
    }
    componentWillMount() {
        console.log('clock----componentWillMount');
    }
    render() {
        console.log('clock---render');
        return(
            <div>
                <h2>今天是{this.state.date}</h2>
            </div>
        )
    }
    componentDidMount(){
        console.log('clock---componentDidMount');
        this.timeID=setInterval(
            ()=>this.tick(),1000
        )
    }
    componentWillUnmount(){
        clearInterval(this.timeID)
    }
}
export default Clock;